jQuery.fn.input_number = function(){
	//catch input: number -> valid , character -> invalid
	var reg = /^[0-9]*$/;
	var update_string = jQuery(this).val();
	
	if(!reg.test(update_string))
	{
		jQuery(this).val("");
		update_string = "";
	}
	
	jQuery(this).bind('keypress',function(event){
		var key = event.charCode ? event.charCode : event.keyCode ? event.keyCode : 0;

		if(key == 8 || key == 46 || key == 13)
		{
			return true;
		}
		var string = jQuery(this).val() + String.fromCharCode(key);
		
		if(reg.test(string))
		{	
			update_string = string;
			return true;
		}
			
		return false;
	});
	
	jQuery(this).bind('keyup',function(event){
		var key = event.charCode ? event.charCode : event.keyCode ? event.keyCode : 0;
		if(key == 8 || key == 46 || key == 13 || key == 37 || key == 39)
		{
			return true;
		}
		if(jQuery.trim(jQuery(this).val()) != "")
			jQuery(this).val(parseInt(jQuery(this).val()));	
	});
	
	jQuery(this).bind('blur',function(event){
		if(jQuery.trim(jQuery(this).val()) != "")
			jQuery(this).val(parseInt(jQuery(this).val()));
	});
	
	var ctrlDown = false;
	var ctrlKey = 17, vKey = 86, cKey = 67;
	jQuery(document).keydown(function(e)
    {
        if (e.keyCode == ctrlKey) ctrlDown = true;
    }).keyup(function(e)
    {
        if (e.keyCode == ctrlKey) ctrlDown = false;
    });
	
	
	jQuery(this).bind('keydown',function(event){
		var key = event.charCode ? event.charCode : event.keyCode ? event.keyCode : 0;
		//if (ctrlDown && (e.keyCode == vKey || e.keyCode == cKey))
		var el = this;
		if(key == 8 || key == 46)
		{
			window.setTimeout(function(){
				var string = jQuery(el).val();
				update_string = string;
			},1)
			return true;
		}
		if (ctrlDown && key == vKey )
		{
			
			window.setTimeout(function(){
				var string = jQuery(el).val();
				if(!reg.test(string))
				{
					jQuery(el).val(update_string);
				}else
				{
					update_string = string;
				}
			},1)
		}
	});
}

function number_format (number, decimals, dec_point, thousands_sep) {	  
  number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
  var n = !isFinite(+number) ? 0 : +number,
    prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
    sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
    dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
    s = '',
    toFixedFix = function (n, prec) {
      var k = Math.pow(10, prec);
      return '' + Math.round(n * k) / k;
    };
  // Fix for IE parseFloat(0.55).toFixed(0) = 0;
  s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
  if (s[0].length > 3) {
    s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
  }
  if ((s[1] || '').length < prec) {
    s[1] = s[1] || '';
    s[1] += new Array(prec - s[1].length + 1).join('0');
  }
  return s.join(dec);
}